/*! phonebar v1.0.0 | (c) created 20190327 | hejm@huayunworld.com */
var baseUrl = './static/newPhone/';
var testHost = 'http://cc.aiccyun.com/';
require.config({
    baseUrl: baseUrl + "lib",
    paths: {
        "jquery": ["jquery"],
        "uc-3.0.4": ["uc-3.0.4"],
        "uc-3.0.6": ["uc-3.0.6"],
        "jquery.md5": ["jquery.md5"]
    },
    waitSeconds: 0
})
define(["jquery", "uc-3.0.4", "uc-3.0.6", "jquery.md5"], function($, uc304, uc305) {
    // 引jquery
    // 验证是否引用jquery
    // if (!$ || !$.fn || !$.fn.jquery) {
    //     alert('在引用之前，先引用jQuery，否则无法使用');
    //     return;
    // }
    // 兼容
    if (typeof Object.assign !== 'function') {
        Object.assign = function(target) {
            'use strict';
            if (target == null) {
                throw new TypeError('Cannot convert undefined or null to object');
            }

            target = Object(target);
            for (var index = 1; index < arguments.length; index++) {
                var source = arguments[index];
                if (source != null) {
                    for (var key in source) {
                        if (Object.prototype.hasOwnProperty.call(source, key)) {
                            target[key] = source[key];
                        }
                    }
                }
            }
            return target;
        };
    }
    if (!Array.prototype.find) {
        Array.prototype.find = function(predicate) {
            'use strict';
            if (this == null) {
                throw new TypeError('Array.prototype.find called on null or undefined');
            }
            if (typeof predicate !== 'function') {
                throw new TypeError('predicate must be a function');
            }
            var list = Object(this);
            var length = list.length >>> 0;
            var thisArg = arguments[1];
            var value;

            for (var i = 0; i < length; i++) {
                value = list[i];
                if (predicate.call(thisArg, value, i, list)) {
                    return value;
                }
            }
            return undefined;
        };
    }
    if (!Array.indexOf) {
        Array.prototype.indexOf = function(obj) {
            for (var i = 0; i < this.length; i++) {
                if (this[i] == obj) {
                    return i;
                }
            }
            return -1;
        }
    }
    var timeFormat = function(timeCode, format) {
            var year = timeCode.getFullYear();
            var month = timeCode.getMonth() + 1;
            var strDate = timeCode.getDate();
            var hour = timeCode.getHours();
            var minutes = timeCode.getMinutes();
            var second = timeCode.getSeconds();
            var timeFormat;
            if (format === null || format === undefined) {
                timeFormat = year + '-' + month + '-' + strDate + ' ' + hour + ':' + minutes + ':' + second;
            } else if (format.toLowerCase() === 'hh:mm:ss') {
                timeFormat = hour + ':' + minutes + ':' + second;
            } else if (format.toLowerCase() === 'yyyy-mm-dd') {
                timeFormat = year + '/' + month + '/' + strDate;
            }
            return timeFormat;
        }
        // 定义扩展函数
    var _p = function(fn) {
        var P = window.newPhone;
        if (P) {
            // 执行传入的函数
            fn(P, $);
        }
    };
    /*
     * 电话条整体构造函数
     */
    (function(window, $) {
        if (window.newPhone) {
            // 重复引用
            alert('一个页面不能重复引用 phone.js 或 phone.min.js ！！！');
            return;
        }
        //（整体）构造函数
        var P = function(pageIndex) {
            // ------------------初始化------------------
            this.clientList = {};
            this.isNeedAlert = true;
            this.initDefaultConfig();
        };
        P.fn = P.prototype;
        P.$body = $('body');
        P.$document = $(document);
        P.$window = $(window);
        P.userAgent = navigator.userAgent;
        P.getComputedStyle = window.getComputedStyle;
        // P.UCObj = UCObj;
        P.uc304 = uc304;
        P.uc305 = uc305;
        // 暴露给全局对象
        window.newPhone = P;
    })(window, $);
    /*
     * 电话状态定义
     */
    _p(function(P, $) {
            var EventStatus = function(btn_login, btn_logout, btn_ready, btn_notready, btn_answer, btn_disconnect, btn_callout, btn_holdon, btn_consult, btn_transfer, btn_callback, btn_meet, btn_monitor, btn_insert, btn_drop, btn_reset, btn_set, btn_cooperation, btn_transferIvr, btn_startmute, btn_endmute, btn_transferSkill, btn_step_meet, btn_whisper, btn_degree) {
                this.btn_login = btn_login; //登入 1
                this.btn_logout = btn_logout; //登出 2
                this.btn_ready = btn_ready; //置闲 3
                this.btn_notready = btn_notready; //置忙 4
                this.btn_answer = btn_answer; //接听 5
                this.btn_disconnect = btn_disconnect; //挂断 6
                this.btn_callout = btn_callout; //外呼 7
                this.btn_holdon = btn_holdon; //保持 8
                this.btn_consult = btn_consult; //咨询 9
                this.btn_transfer = btn_transfer; //转接 10
                this.btn_callback = btn_callback; //接回 11
                this.btn_meet = btn_meet; //会议 12
                this.btn_monitor = btn_monitor; //监听 13
                this.btn_insert = btn_insert; //强插 14
                this.btn_drop = btn_drop; //强拆 15
                this.btn_reset = btn_reset; //重置 16
                this.btn_set = btn_set; //设置 17
                this.btn_cooperation = btn_cooperation; //协作 18
                this.btn_transferIvr = btn_transferIvr; //转接IVR
                this.btn_startmute = btn_startmute; //开始静音
                this.btn_endmute = btn_endmute; //结束静音
                this.btn_transferSkill = btn_transferSkill; //转接技能组
                this.btn_step_meet = btn_step_meet; //单步会议
                this.btn_whisper = btn_whisper; //密语
                this.btn_degree = btn_degree; //满意度
            }
            P.EventStatus = EventStatus;
        })
        /*
         * 全局配置
         */
    _p(function(P, $) {
            P.config = {};
            // 默认 菜单配置
            P.config.menus = [
                'btn_login',
                'btn_logout',
                'btn_ready',
                'btn_notready',
                'btn_answer',
                'btn_disconnect',
                'btn_callout',
                'btn_holdon',
                'btn_consult',
                'btn_transfer',
                'btn_callback',
                'btn_meet',
                'btn_monitor',
                'btn_insert',
                'btn_drop',
                'btn_reset',
                'btn_set',
                'btn_cooperation', // 坐席协作
                'btn_transferIvr', // 转接IVR
                'btn_startmute', // 开始静音
                'btn_endmute', // 结束静音
                'btn_transferSkill', // 转接技能组
                'btn_step_meet', // 单步会议
                'btn_whisper', //密语
                'btn_degree' //转满意度
            ];
            P.config.httpServerAddress = '192.168.0.181'
            P.config.stateList = {
                AgentStatus_Init: 'Init',
                AgentStatus_Login: '置忙',
                AgentStatus_Logout: '未登录',
                AgentStatus_Ready: '置闲',
                AgentStatus_Otherwork: '置忙',
                AgentStatus_ACW: '整理',
                AgentStatus_Locked: '锁定中',
                AgentStatus_Alerting: '振铃中',
                AgentStatus_Connecting: '振铃中',
                AgentStatus_Connected_Normal: '通话中',
                AgentStatus_Connected_Internal: '通话中',
                AgentStatus_Disconnected: null,
                AgentStatus_Suspended: '保持中',
                AgentStatus_Held: '保持中',
                AgentStatus_Consulting: '振铃中', // 咨询振铃中
                AgentStatus_Consulted: '咨询中',
                AgentStatus_Conferenced: '会议中',
                AgentStatus_Monitored: '监听中',
                AgentStatus_Inserted: '通话中',
                AgentStatus_Unkown: 'unknown',
                AgentStatus_Connected_Mute: '静音中'
            }
            P.config.eventList = {
                AgentStatus_Init: new P.EventStatus(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
                AgentStatus_Login: new P.EventStatus(0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0), //可外呼
                AgentStatus_Logout: new P.EventStatus(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
                AgentStatus_Ready: new P.EventStatus(0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0),
                AgentStatus_Otherwork: new P.EventStatus(0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0), // 可外呼 可监听
                AgentStatus_ACW: new P.EventStatus(0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0), // 不可外呼
                AgentStatus_Locked: new P.EventStatus(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0), // 不需要
                AgentStatus_Alerting: new P.EventStatus(0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0),
                AgentStatus_Connecting: new P.EventStatus(0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0),
                AgentStatus_Connected_Normal: new P.EventStatus(0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1),
                AgentStatus_Connected_Internal: new P.EventStatus(0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0),
                AgentStatus_Disconnected: new P.EventStatus(0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0),
                AgentStatus_Suspended: new P.EventStatus(0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0), //这里采用了接回的样式,原本全是0
                AgentStatus_Held: new P.EventStatus(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0),
                AgentStatus_Consulting: new P.EventStatus(0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0),
                AgentStatus_Consulted: new P.EventStatus(0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0),
                AgentStatus_Conferenced: new P.EventStatus(0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0),
                AgentStatus_Monitored: new P.EventStatus(0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0),
                AgentStatus_Inserted: new P.EventStatus(0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
                AgentStatus_Unkown: new P.EventStatus(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0),
                AgentStatus_noAnswer: new P.EventStatus(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0),
                AgentStatus_Connected_Mute: new P.EventStatus(0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0)
            }
            P.config.stateDescription = {}
        })
        /*
         * 对象配置
         */
    _p(function(P, $) {
            P.fn.initDefaultConfig = function() {
                var phone = this;
                // 将 config 配置参数 定义到具体对象上
                phone.config = $.extend({}, P.config);
                // 电话条 初始化 及 登录参数
                phone.loginConfig = {};
                // 是否初始化成功参数
                //phone.initializeState = false;
                phone.initializeState = true;
                // 初始化菜单集合
                phone.menus = {};
                //回调状态保存
                phone.EventType = '';
                //将要获取的回调状态保存
                phone.toEventType = '';
                phone.renderEvents = {};
            };
        })
        /*
         * 电话条切换小状态按钮
         */
    _p(function(P, $) {
            P.fn.changeSmallStatus = function(status, render) {
                var changeSmallStatusUrl = testHost + 'smallStatus/smallStatus/api/getSmallStatus?entId=' + window.phoneUserInfo.entId + '&agentId=' + window.phoneUserInfo.agentID + '&agentPwd=' + $.md5(window.phoneUserInfo.password).toUpperCase() + '&status=' + status + '&operaTime=' + timeFormat(new Date());
                $.ajax({
                    url: changeSmallStatusUrl,
                    dataType: 'jsonp',
                    type: "GET",
                    success: function(res) {
                        // 修改小状态的样式
                        render(res);
                    }
                })
            }
        })
        /*
         * 电话条登录事件
         */
    _p(function(P, $) {
            P.fn.login = function() {
                window.$phoarraybox.show()
                var phone = this;
                // 需要取到登录时的地址
                phone.loginConfig = window.phoneUserInfo;
                var LoginURL = window.phoneUserInfo.httpServerAddress;
                var agentId = window.phoneUserInfo.agentID;
                var password = window.phoneUserInfo.password;
                var EnterpriseID = window.phoneUserInfo.entId;
                var agentDN = window.phoneUserInfo.sipUser;
                var TerminalType = window.phoneUserInfo.TerminalType;
                phone.renderEvents.loginingRender();
                // phone.ucObj = new P.UCObj(P.$window[0],P.$document[0]);
                // 执行 pass 异步请求
                $.ajax({
                    // type: 'get',
                    async: false,
                    url: testHost + 'cca/paas/agentLoginInfo?entId=' + EnterpriseID + '&callback=?',
                    dataType: "jsonp",
                    jsonp: "callback",
                    success: function(data) {
                        var LoginURL = data.wsUrl;
                        var version = data.version;
                        var newPassword;
                        if (version === 'uc-3.0.4') {
                            newPassword = password;
                            phone.ucObj = new P.uc304(P.$window[0], P.$document[0]);
                            // 发起请求
                            phone.ucObj.loginex(LoginURL, agentId, newPassword, EnterpriseID, agentDN, TerminalType, loginCallBack.bind(phone))
                        } else {
                            newPassword = $.md5(password).toUpperCase();
                            phone.ucObj = new P.uc305(P.$window[0], P.$document[0]);
                            // 判断是否已登陆
                            phone.ucObj.GetAgentState(function(res) {
                                if (res.Code === '0') {
                                    // 需要查询的是当前坐席 而且是当前坐席已经是登录状态
                                    if ((res.IsLogon === 'true' && res.EntId === EnterpriseID && res.AgentId === agentId) && res.AgentStatus !== 'AgentStatus_Logout') {
                                        phone.ucObj.doSetPageIndex(new Date().getTime()); // 多页面应用
                                        // 恢复初始化状态
                                        loginCallBack({ Code: '0' })
                                        phone.getEventStatus(res.Event, res.AgentStateTime);
                                    } else {
                                        // 发起请求
                                        phone.ucObj.loginex(LoginURL, agentId, newPassword, EnterpriseID, agentDN, TerminalType, loginCallBack.bind(phone))
                                    }
                                }
                            });
                        }

                        function loginCallBack(data) {
                            if (data.Code === '0') {
                                phone.renderEvents.loginRender(data);
                                // 开始轮询
                                phone.ucObj.start(phone.getEventStatus.bind(phone));
                                // 查询外显号码(可能获取到多个)
                                phone.ucObj.doGetShowANI(function(data) {
                                        if (data.Code === '0') {
                                            //将外显号码曝出
                                            phone.renderEvents.explicitNumRender(data['Msg']);
                                        }
                                    })
                                    //  获取 电话条 小状态内容
                                $.ajax({
                                    url: testHost + 'smallStatus/smallStatus/api/querySmallStatusTypeByEntId?entId=' + window.phoneUserInfo.entId,
                                    type: "GET",
                                    dataType: "jsonp", //指定服务器返回的数据类型
                                    success: function(res) {
                                        if (res.status === '0' && res.data.length > 0) {
                                            phone.smallStatus = res.data;
                                        } else {
                                            phone.smallStatus = '置忙'
                                        }
                                        phone.renderEvents.smallStatusRender(phone.smallStatus);
                                    },
                                    error: function() {
                                        phone.smallStatus = '置忙';
                                        phone.renderEvents.smallStatusRender(phone.smallStatus);
                                    }
                                })
                            } else {
                                phone.renderEvents.loginRender(data)
                            }
                        }
                    },
                    error: function() {
                        let data = { Code: 2 }
                        phone.renderEvents.loginRender(data)
                    }
                })
            }
        })
        /*
         *电话条登出事件
         */
    _p(function(P, $) {
            P.fn.logout = function() {
                var phone = this;
                if (phone.ucObj) {
                    phone.ucObj.doLogOut(function(data) {
                        phone.renderEvents.logoutRender();
                        if (data.Code === '0') {
                            phone.ucObj.stopObj();
                        }
                    });
                } else {
                    phone.renderEvents.logoutRender();
                }
            }
        })
        /*
         * menu 构造函数
         */
    _p(function(P, $) {
        // 定义构造函数
        var Menu = function(opt) {
            this.phone = opt.phone;
            this.menuId = opt.id;
        };
        P.Menu = Menu;
    });
    /*
     * 菜单事件
     */
    _p(function(P, $) {
        var createMenuFn = [];
        P.createMenu = function(fn) {
            createMenuFn.push(fn);
        };
        P.fn.defineEvent = function(menuId, obj) {
                var phone = this;
                if (obj === undefined) {
                    phone.menus[menuId].clickEvent();
                } else if (obj['callNum']) { // 外拨传参
                    // phone.menus[menuId].clickEvent(obj['callNum'], obj['showNum']);
                    // callNum-外呼号码 showNum-外显号码 isNeedAlert:传入是否弹屏参数
                    phone.menus[menuId].clickEvent(obj);
                } else if (obj['consultType'] && obj['targetNum']) { // 咨询传参
                    phone.menus[menuId].clickEvent(obj['consultType'], obj['targetNum']);
                } else if (obj['conferenceParty']) { //监听传参
                    phone.menus[menuId].clickEvent(obj['conferenceParty']);
                }
            }
            // 添加菜单
        P.fn.addAllMenus = function() {
            var phone = this;
            var menuIds = phone.config.menus;

            // 检验 menuId 是否在配置中存在
            function check(menuId) {
                if (menuIds.indexOf(menuId) >= 0) {
                    return true;
                }
                return false;
            }
            $.each(createMenuFn, function(k, fn) {
                fn.call(phone, check); // 改变this指向，同时传入参数check
            })
        }
    });
    /*
     * 登入菜单
     */
    _p(function(P, $) {
        P.createMenu(function(check) {
            var menuId = 'btn_login';
            if (!check(menuId)) {
                return;
            }
            var phone = this;
            // 创建 menu 对象
            var menu = new P.Menu({
                phone: phone,
                id: menuId
            });
            menu.clickEvent = function() {
                    var initStatus = phone.initializeState;
                    if (initStatus && phone.toEventType !== 'AgentStatus_Login') {
                        //需要初始化成功 同时 按钮状态可点
                        phone.login();
                    }
                    phone.toEventType = 'AgentStatus_Login'
                    if (phone.toEventType !== phone.EventType) {
                        // 状态没有返回 所有按钮将不能点
                        phone.customgetStateFn(phone.config.eventList['AgentStatus_noAnswer'])
                    }
                }
                // 增加到editor对象中
            phone.menus[menuId] = menu;
        });
    });
    /*
     * 登出菜单
     */
    _p(function(P, $) {
        P.createMenu(function(check) {
            var menuId = 'btn_logout';
            if (!check(menuId)) {
                return;
            }
            var phone = this;
            // 创建 menu 对象
            var menu = new P.Menu({
                phone: phone,
                id: menuId
            });
            menu.clickEvent = function() {
                    if (phone.EventType === '') {
                        phone.toEventType = '';
                        phone.logout();
                        return;
                    }
                    var btnStatus = phone.config.eventList[phone.EventType][menuId];
                    // 登录失败  phone.EventType 是 空字符串
                    if (btnStatus && phone.toEventType !== 'AgentStatus_Logout') {
                        phone.logout();
                    }
                    phone.toEventType = 'AgentStatus_Logout'
                    if (phone.toEventType !== phone.EventType) {
                        // 状态没有返回 所有按钮将不能点
                        phone.customgetStateFn(phone.config.eventList['AgentStatus_noAnswer'])
                    }
                }
                // 增加到editor对象中
            phone.menus[menuId] = menu;
        });
    });
    /*
     * 置闲菜单
     */
    _p(function(P, $) {
        P.createMenu(function(check) {
            var menuId = 'btn_ready';
            if (!check(menuId)) {
                return;
            }
            var phone = this;
            // 创建 menu 对象
            var menu = new P.Menu({
                phone: phone,
                id: menuId
            });
            menu.clickEvent = function() {
                    // 查看状态 可点的情况下，执行置闲
                    var btnStatus = phone.config.eventList[phone.EventType][menuId];

                    if (btnStatus && phone.toEventType !== 'AgentStatus_Ready') {
                        phone.ucObj.doReady();
                    };
                    phone.toEventType = 'AgentStatus_Ready';
                    if (phone.toEventType !== phone.EventType) {
                        // 状态没有返回 所有按钮将不能点
                        phone.customgetStateFn(phone.config.eventList['AgentStatus_noAnswer'])
                    }
                }
                // 增加到editor对象中
            phone.menus[menuId] = menu;
        });
    });
    /*
     * 置忙菜单
     */
    _p(function(P, $) {
        P.createMenu(function(check) {
            var menuId = 'btn_notready';
            if (!check(menuId)) {
                return;
            }

            var phone = this;

            // 创建 menu 对象
            var menu = new P.Menu({
                phone: phone,
                id: menuId
            });
            menu.clickEvent = function() {
                    var btnStatus = phone.config.eventList[phone.EventType][menuId];

                    if (btnStatus && phone.toEventType !== 'AgentStatus_Otherwork') {
                        phone.ucObj.doNotReady();
                    }
                    phone.toEventType = 'AgentStatus_Otherwork'
                    if (phone.toEventType !== phone.EventType) {
                        // 状态没有返回 所有按钮将不能点
                        phone.customgetStateFn(phone.config.eventList['AgentStatus_noAnswer'])
                    }
                }
                // 增加到editor对象中
            phone.menus[menuId] = menu;
        });
    });
    /*
     * 接听菜单
     */
    _p(function(P, $) {
        P.createMenu(function(check) {
            var menuId = 'btn_answer';
            if (!check(menuId)) {
                return;
            }

            var phone = this;

            // 创建 menu 对象
            var menu = new P.Menu({
                phone: phone,
                id: menuId
            });
            menu.clickEvent = function() {
                    var btnStatus = phone.config.eventList[phone.EventType][menuId];
                    // 有可能是两种  正常接通/咨询接通（AgentStatus_Consulted）
                    phone.toEventType = 'AgentStatus_Connected_Normal'
                    if (btnStatus) {
                        phone.ucObj.doAnswer();
                    }
                    if (phone.toEventType !== phone.EventType || 'AgentStatus_Consulted' !== phone.EventType) {
                        // 状态没有返回 所有按钮将不能点
                        phone.customgetStateFn(phone.config.eventList['AgentStatus_noAnswer'])
                    }
                }
                // 增加到editor对象中
            phone.menus[menuId] = menu;
        });
    });
    /*
     * 挂断菜单
     */
    _p(function(P, $) {
        P.createMenu(function(check) {
            var menuId = 'btn_disconnect';
            if (!check(menuId)) {
                return;
            }

            var phone = this;

            // 创建 menu 对象
            var menu = new P.Menu({
                phone: phone,
                id: menuId
            });
            menu.clickEvent = function() {
                    var btnStatus = phone.config.eventList[phone.EventType][menuId];
                    // AgentStatus_ACW(事后整理) AgentStatus_Disconnected 两个状态一起返回
                    phone.toEventType = 'AgentStatus_ACW' + 'AgentStatus_Disconnected';
                    if (btnStatus) {
                        phone.ucObj.doDisconnect();
                    }
                    // if (phone.toEventType !== phone.EventType) {
                    if (phone.toEventType.indexOf(phone.EventType) === -1) {
                        // 状态没有返回 所有按钮将不能点
                        phone.customgetStateFn(phone.config.eventList['AgentStatus_noAnswer'])
                    }
                }
                // 增加到editor对象中
            phone.menus[menuId] = menu;
        });
    });
    /*
     * 外呼菜单
     */
    _p(function(P, $) {
        P.createMenu(function(check) {
            var menuId = 'btn_callout';
            if (!check(menuId)) {
                return;
            }
            var phone = this;

            // 创建 menu 对象
            var menu = new P.Menu({
                phone: phone,
                id: menuId
            });
            menu.clickEvent = function(obj) {
                    var callNum = obj.callNum,
                        showNum = obj.showNum;
                    if (obj.isNeedAlert === false) {
                        phone.isNeedAlert = false;
                    }
                    var btnStatus = phone.config.eventList[phone.EventType][menuId];
                    phone.toEventType = 'AgentStatus_Alerting'
                    // 置闲也可以外呼
                    if (btnStatus) {
                        // 收到 Alerting振铃事件 才能去调 doAnswer
                        if (showNum === '') {
                            phone.ucObj.doCallOut(callNum, phone.config.explicitNum);
                        } else {
                            phone.ucObj.doCallOut(callNum, showNum);
                        }
                    }
                    if (phone.toEventType !== phone.EventType) {
                        // 状态没有返回 所有按钮将不能点
                        phone.customgetStateFn(phone.config.eventList['AgentStatus_noAnswer'])
                    }
                }
                // 增加到editor对象中
            phone.menus[menuId] = menu;
        });
    });
    /*
     * 客户被保持保持菜单
     */
    _p(function(P, $) {
        P.createMenu(function(check) {
            var menuId = 'btn_holdon';
            if (!check(menuId)) {
                return;
            }

            var phone = this;

            // 创建 menu 对象
            var menu = new P.Menu({
                phone: phone,
                id: menuId
            });
            menu.clickEvent = function() {
                    var btnStatus = phone.config.eventList[phone.EventType][menuId];
                    phone.toEventType = 'AgentStatus_Suspended'
                    if (btnStatus) {
                        phone.ucObj.doHold();
                    }
                    if (phone.toEventType !== phone.EventType) {
                        // 状态没有返回 所有按钮将不能点
                        phone.customgetStateFn(phone.config.eventList['AgentStatus_noAnswer'])
                    }
                }
                // 增加到editor对象中
            phone.menus[menuId] = menu;
        });
    });
    /*
     * 接回菜单
     */
    _p(function(P, $) {
        P.createMenu(function(check) {
            var menuId = 'btn_callback';
            if (!check(menuId)) {
                return;
            }

            var phone = this;

            // 创建 menu 对象
            var menu = new P.Menu({
                phone: phone,
                id: menuId
            });
            menu.clickEvent = function() {
                    var btnStatus = phone.config.eventList[phone.EventType][menuId];
                    phone.toEventType = 'AgentStatus_Connected_Normal'
                    if (btnStatus) {
                        phone.ucObj.doRetrive();
                    }
                    if (phone.toEventType !== phone.EventType) {
                        // 状态没有返回 所有按钮将不能点
                        phone.customgetStateFn(phone.config.eventList['AgentStatus_noAnswer'])
                    }
                }
                // 增加到editor对象中
            phone.menus[menuId] = menu;
        });
    });
    /*
     * 咨询菜单
     */
    _p(function(P, $) {
        P.createMenu(function(check) {
            var menuId = 'btn_consult';
            if (!check(menuId)) {
                return;
            }

            var phone = this;

            // 创建 menu 对象
            var menu = new P.Menu({
                phone: phone,
                id: menuId
            });
            menu.clickEvent = function(consultType, targetNum) {
                    var btnStatus = phone.config.eventList[phone.EventType][menuId];
                    phone.toEventType = 'AgentStatus_Consulting'
                    if (btnStatus) {
                        phone.ucObj.doConsulting(consultType, targetNum);
                    }
                    if (phone.toEventType !== phone.EventType) {
                        // 状态没有返回 所有按钮将不能点
                        phone.customgetStateFn(phone.config.eventList['AgentStatus_noAnswer'])
                    }
                }
                // 增加到editor对象中
            phone.menus[menuId] = menu;
        });
    });
    /*
     * 转接菜单
     */
    _p(function(P, $) {
        P.createMenu(function(check) {
            var menuId = 'btn_transfer';
            if (!check(menuId)) {
                return;
            }

            var phone = this;

            // 创建 menu 对象
            var menu = new P.Menu({
                phone: phone,
                id: menuId
            });
            menu.clickEvent = function() {
                    var btnStatus = phone.config.eventList[phone.EventType][menuId];
                    phone.toEventType = 'AgentStatus_Disconnected'
                    if (btnStatus) {
                        phone.ucObj.doAdressShift();
                    }
                    if (phone.toEventType !== phone.EventType) {
                        // 状态没有返回 所有按钮将不能点
                        phone.customgetStateFn(phone.config.eventList['AgentStatus_noAnswer'])
                    }
                }
                // 增加到editor对象中
            phone.menus[menuId] = menu;
        });
    });
    /*
     * 会议菜单
     */
    _p(function(P, $) {
        P.createMenu(function(check) {
            var menuId = 'btn_meet';
            if (!check(menuId)) {
                return;
            }

            var phone = this;

            // 创建 menu 对象
            var menu = new P.Menu({
                phone: phone,
                id: menuId
            });
            menu.clickEvent = function() {
                    var btnStatus = phone.config.eventList[phone.EventType][menuId];
                    phone.toEventType = 'AgentStatus_Conferenced'
                    if (btnStatus) {
                        phone.ucObj.doMeeting();
                    }
                    if (phone.toEventType !== phone.EventType) {
                        // 状态没有返回 所有按钮将不能点
                        phone.customgetStateFn(phone.config.eventList['AgentStatus_noAnswer'])
                    }
                }
                // 增加到editor对象中
            phone.menus[menuId] = menu;
        });
    });

    /*
     * 单步会议
     */
    _p(function(P, $) {
        P.createMenu(function(check) {
            var menuId = 'btn_step_meet';
            if (!check(menuId)) {
                return;
            }
            console.log('phone.js start doStepMeeting');
            var phone = this;

            // 创建 menu 对象
            var menu = new P.Menu({
                phone: phone,
                id: menuId
            });
            menu.clickEvent = function(consultType, targetNum) {
                    var btnStatus = phone.config.eventList[phone.EventType][menuId];
                    phone.toEventType = 'AgentStatus_Consulting'
                    if (btnStatus) {
                        phone.ucObj.doStepMeeting(consultType, targetNum);
                    }
                    if (phone.toEventType !== phone.EventType) {
                        // 状态没有返回 所有按钮将不能点
                        phone.customgetStateFn(phone.config.eventList['AgentStatus_noAnswer'])
                    }
                }
                // 增加到editor对象中
            phone.menus[menuId] = menu;
        });
    });
        /*
        * 坐席转IVR
        */
       _p(function (P, $) {
        P.createMenu(function (check) {
            var menuId = 'btn_transferIvr';
            if (!check(menuId)) {
                return;
            }

            var phone = this;

            // 创建 menu 对象
            var menu = new P.Menu({
                phone: phone,
                id: menuId
            });
            menu.clickEvent = function() {
                var btnStatus = phone.config.eventList[phone.EventType][menuId];
                phone.toEventType = 'AgentStatus_ACW'
                if(btnStatus) {
                    phone.ucObj.doToIVR();
                }
                if (phone.toEventType !== phone.EventType) {
                    // 状态没有返回 所有按钮将不能点
                    phone.customgetStateFn(phone.config.eventList['AgentStatus_noAnswer'])
                }
            }
            // 增加到editor对象中
            phone.menus[menuId] = menu;
        });
    });

       /*
        * 坐席转满意度
        */
       _p(function (P, $) {
        P.createMenu(function (check) {
            var menuId = 'btn_degree';
            if (!check(menuId)) {
                return;
            }

            var phone = this;

            // 创建 menu 对象
            var menu = new P.Menu({
                phone: phone,
                id: menuId
            });
            menu.clickEvent = function() {
                var btnStatus = phone.config.eventList[phone.EventType][menuId];
                phone.toEventType = 'AgentStatus_ACW'
                if(btnStatus) {
                    phone.ucObj.doDisconnect();
                }
                if (phone.toEventType !== phone.EventType) {
                    // 状态没有返回 所有按钮将不能点
                    phone.customgetStateFn(phone.config.eventList['AgentStatus_noAnswer'])
                }
            }
            // 增加到editor对象中
            phone.menus[menuId] = menu;
        });
    });

        /*
        * 开始静音
        */
       _p(function (P, $) {
        P.createMenu(function (check) {
            var menuId = 'btn_startmute';
            if (!check(menuId)) {
                return;
            }

            var phone = this;

            // 创建 menu 对象
            var menu = new P.Menu({
                phone: phone,
                id: menuId
            });
            menu.clickEvent = function() {
                phone.ucObj.doSetMicMute('true');
                phone.customgetStateFn(phone.config.eventList['AgentStatus_Connected_Mute']);
            }
            // 增加到editor对象中
            phone.menus[menuId] = menu;
        });
    });

       /*
        * 结束静音
        */
       _p(function (P, $) {
        P.createMenu(function (check) {
            var menuId = 'btn_endmute';
            if (!check(menuId)) {
                return;
            }

            var phone = this;

            // 创建 menu 对象
            var menu = new P.Menu({
                phone: phone,
                id: menuId
            });
            menu.clickEvent = function() {
                phone.ucObj.doSetMicMute('false');
                phone.customgetStateFn(phone.config.eventList['AgentStatus_Connected_Normal']);
            }
            // 增加到editor对象中
            phone.menus[menuId] = menu;
        });
    });

       /*
        * 坐席转技能组
        */
       _p(function (P, $) {
        P.createMenu(function (check) {
            var menuId = 'btn_transferSkill';
            if (!check(menuId)) {
                return;
            }

            var phone = this;

            // 创建 menu 对象
            var menu = new P.Menu({
                phone: phone,
                id: menuId
            });
            menu.clickEvent = function(skillGroup) {
                var btnStatus = phone.config.eventList[phone.EventType][menuId];
                phone.toEventType = 'AgentStatus_ACW'
                if(btnStatus) {
                    phone.ucObj.doTransferSkill(skillGroup);
                }
                if (phone.toEventType !== phone.EventType) {
                    // 状态没有返回 所有按钮将不能点
                    phone.customgetStateFn(phone.config.eventList['AgentStatus_noAnswer'])
                }
            }
            // 增加到editor对象中
            phone.menus[menuId] = menu;
        });
    });
    /*
     * 监听菜单
     */
    _p(function(P, $) {
        P.createMenu(function(check) {
            var menuId = 'btn_monitor';
            if (!check(menuId)) {
                return;
            }

            var phone = this;

            // 创建 menu 对象
            var menu = new P.Menu({
                phone: phone,
                id: menuId
            });
            menu.clickEvent = function(conferenceParty) {
                    var btnStatus = phone.config.eventList[phone.EventType][menuId];
                    phone.toEventType = 'AgentStatus_Monitored'
                    if (btnStatus) {
                        phone.ucObj.doListen(conferenceParty);
                    }
                    if (phone.toEventType !== phone.EventType) {
                        // 状态没有返回 所有按钮将不能点
                        phone.customgetStateFn(phone.config.eventList['AgentStatus_noAnswer'])
                    }
                }
                // 增加到editor对象中
            phone.menus[menuId] = menu;
        });
    });
    /*
     * 强拆菜单
     */
    _p(function(P, $) {
        P.createMenu(function(check) {
            var menuId = 'btn_drop';
            if (!check(menuId)) {
                return;
            }

            var phone = this;

            // 创建 menu 对象
            var menu = new P.Menu({
                phone: phone,
                id: menuId
            });
            menu.clickEvent = function() {
                    var btnStatus = phone.config.eventList[phone.EventType][menuId];
                    phone.toEventType = 'AgentStatus_droped'
                    if (btnStatus) {
                        phone.ucObj.doDrop();
                    }
                    if (phone.toEventType !== phone.EventType) {
                        // 状态没有返回 所有按钮将不能点
                        phone.customgetStateFn(phone.config.eventList['AgentStatus_noAnswer'])
                    }
                }
                // 增加到editor对象中
            phone.menus[menuId] = menu;
        });
    });
    /*
     * 强插菜单
     */
    _p(function(P, $) {
        P.createMenu(function(check) {
            var menuId = 'btn_insert';
            if (!check(menuId)) {
                return;
            }

            var phone = this;

            // 创建 menu 对象
            var menu = new P.Menu({
                phone: phone,
                id: menuId
            });
            menu.clickEvent = function() {
                    var btnStatus = phone.config.eventList[phone.EventType][menuId];
                    phone.toEventType = 'AgentStatus_Inserted'
                    if (btnStatus) {
                        phone.ucObj.doInsert();
                    }
                    if (phone.toEventType !== phone.EventType) {
                        // 状态没有返回 所有按钮将不能点
                        phone.customgetStateFn(phone.config.eventList['AgentStatus_noAnswer'])
                    }
                }
                // 增加到editor对象中
            phone.menus[menuId] = menu;
        });
    });
   /*
     * 密语菜单
     */
   _p(function(P, $) {
    P.createMenu(function(check) {
        var menuId = 'btn_whisper';
        if (!check(menuId)) {
            return;
        }

        var phone = this;

        // 创建 menu 对象
        var menu = new P.Menu({
            phone: phone,
            id: menuId
        });
        menu.clickEvent = function() {
                var btnStatus = phone.config.eventList[phone.EventType][menuId];
                phone.toEventType = 'AgentStatus_Monitored'
                if (btnStatus) {
                    phone.ucObj.doWhisper();
                }
                if (phone.toEventType !== phone.EventType) {
                    // 状态没有返回 所有按钮将不能点
                    phone.customgetStateFn(phone.config.eventList['AgentStatus_noAnswer'])
                }
            }
            // 增加到editor对象中
            phone.menus[menuId] = menu;
        });
    });
    /*
     * 坐席被保持菜单（IVR协作） 还没有做
     */
    _p(function(P, $) {
        P.createMenu(function(check) {
            var menuId = 'btn_cooperation';
            if (!check(menuId)) {
                return;
            }

            var phone = this;

            // 创建 menu 对象
            var menu = new P.Menu({
                phone: phone,
                id: menuId
            });
            menu.clickEvent = function() {
                    var btnStatus = phone.config.eventList[phone.EventType][menuId];
                    phone.toEventType = 'AgentStatus_Held'
                    if (btnStatus) {
                        phone.ucObj.doAssistIVRServicer();
                    }
                    if (phone.toEventType !== phone.EventType) {
                        // 状态没有返回 所有按钮将不能点
                        phone.customgetStateFn(phone.config.eventList['AgentStatus_noAnswer'])
                    }
                }
                // 增加到editor对象中
            phone.menus[menuId] = menu;
        });
    });
    /*
     * 重置菜单
     */
    _p(function(P, $) {
        P.createMenu(function(check) {
            var menuId = 'btn_reset';
            if (!check(menuId)) {
                return;
            }

            var phone = this;

            // 创建 menu 对象
            var menu = new P.Menu({
                phone: phone,
                id: menuId
            });
            menu.clickEvent = function() {
                    var btnStatus = phone.config.eventList[phone.EventType][menuId];
                    phone.toEventType = 'AgentStatus_Otherwork'
                    if (btnStatus) {
                        phone.ucObj.doReset();
                    }
                    if (phone.toEventType !== phone.EventType) {
                        // 状态没有返回 所有按钮将不能点
                        phone.customgetStateFn(phone.config.eventList['AgentStatus_noAnswer'])
                    }
                }
                // 增加到editor对象中
            phone.menus[menuId] = menu;
        });
    });
    /*
     * 设置菜单
     */
    _p(function(P, $) {
        P.createMenu(function(check) {
            var menuId = 'btn_set';
            if (!check(menuId)) {
                return;
            }

            var phone = this;

            // 创建 menu 对象
            var menu = new P.Menu({
                phone: phone,
                id: menuId
            });
            menu.clickEvent = function() {
                    var btnStatus = phone.config.eventList[phone.EventType][menuId];
                    // phone.toEventType = 'AgentStatus_ACW'
                    if (btnStatus) {
                        // phone.ucObj.doAnswer();
                    }
                    // if (phone.toEventType !== phone.EventType) {
                    //     // 状态没有返回 所有按钮将不能点
                    //     phone.customgetStateFn(phone.config.eventList['AgentStatus_Unkown'])
                    // }
                }
                // 增加到editor对象中
            phone.menus[menuId] = menu;
        });
    });
    /*
     * 发布订阅模式，用于对接方，可以任意监听各种电话状态
     */

    _p(function(P, $) {
            P.fn.listen = function(key, fn) {
                    if (!this.clientList[key]) {
                        this.clientList[key] = [];
                    }
                    this.clientList[key].push(fn);

                },
                P.fn.trigger = function() {
                    var key = Array.prototype.shift.call(arguments),
                        fns = this.clientList[key];
                    if (!fns || fns.length === 0) {
                        return false;
                    }
                    for (var i = 0, fn; fn = fns[i++];) {
                        fn.apply(this, arguments);
                    }
                }
        })
        /*
         * 轮询回调处理
         */
    _p(function(P) {
            // 处理状态文字显示
            function getStateTxt(EventType, CallDetailEvent) {
                var phone = this;
                var stateTxt = null;
                if (EventType === 'AgentStatus_Disconnected') return;
                stateTxt = phone.config.stateList[EventType];
                if (CallDetailEvent === 'CA_CALL_EVENT_OUTBOUND_CONNECTED_TP') { // 外呼本方接通
                    stateTxt = '振铃中'
                } else if (CallDetailEvent === 'CA_CALL_EVENT_OUTBOUND_CONNECTED_OP') { // 外呼对方接通
                    stateTxt = '通话中'
                }
                return stateTxt;
            }
            P.fn.getEventStatus = function(data, AgentStateTime) {
                var phone = this;
                var EventType = data.EventType;
                var CallDetailEvent = data.CallDetailEvent;
                if (AgentStateTime) { data.AgentStateTime = AgentStateTime }
                if (EventType) {
                    //同时将值传递出去
                    phone.EventType = EventType;
                    phone.CallDetailEvent = CallDetailEvent;
                    // 这种条件情况不需要将状态改变 传递
                    // consulted 分为 区分
                    if (EventType === 'AgentStatus_Consulted' && CallDetailEvent === 'CA_CALL_EVENT_CONSULT_CONNECTED_TP') { // 咨询本方应答
                        phone.customgetStateFn(new P.EventStatus(0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0), getStateTxt.call(phone, EventType, CallDetailEvent), data);
                        // 外呼振铃之后可挂断
                        this.trigger('connected', data)
                    } else if (EventType === 'AgentStatus_Connected_Normal' && CallDetailEvent === 'CA_CALL_EVENT_OUTBOUND_CONNECTED_TP') {
                        phone.customgetStateFn(new P.EventStatus(0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0), getStateTxt.call(phone, EventType, CallDetailEvent), data);
                        this.trigger('connected', data)
                    } else {
                        phone.customgetStateFn(phone.config.eventList[EventType], getStateTxt.call(phone, EventType, CallDetailEvent), data);
                    }
                    // unknow 状态 进行 重新恢复
                    if (EventType === 'AgentStatus_Unkown') {
                        phone.isNeedAlert = true;
                        phone.ucObj.GetAgentState(function(res) {
                            if (res.Code === '0') {
                                phone.getEventStatus(res.Event);
                            }
                        })
                    }
                    //外呼本方振铃时 需手动调接听
                    if (CallDetailEvent === 'CA_CALL_EVENT_OUTBOUND_ALERTING_TP') {
                        phone.ucObj.doAnswer();
                    }
                    //监听振铃需要调用接听接口
                    if (CallDetailEvent === 'CA_CALL_EVENT_MONITOR_ALERTING') {
                        phone.ucObj.doAnswer();
                    }
                    // 协作处理
                    if (CallDetailEvent === 'CA_CALL_EVENT_CONSULT_RETRIEVE') {
                        phone.ucObj.doGetAssociateData('SD', function(data) {
                            if (data.Msg.indexOf(";msg:") !== -1) {
                                if (data.Msg.indexOf(";msg:true") > 0) {
                                    alert("用户输入密码正确");
                                } else {
                                    alert("用户输入密码错误");
                                }
                            }
                        });
                    }

                    // 随路数据
                    var m_IVRData = data.IVRData;
                    if (m_IVRData != null) {
                        if (m_IVRData.indexOf("cardNo") > 0) {
                            var ivrDataList = m_IVRData.split("cardNo:");
                            data.IVRData = "随路数据_卡号: " + ivrDataList[1];
                        }
                    }

                    // 处理弹屏事件 外呼
                    if (EventType === 'AgentStatus_Connecting' && CallDetailEvent === 'CA_CALL_EVENT_OUTBOUND_ALERTING_OP') {
                        phone.AlertScreenFn(data, 0, phone.isNeedAlert);
                        phone.isNeedAlert = true;
                        this.trigger('alerting', data)
                    }
                    // 处理弹屏事件 内呼
                    if (EventType === 'AgentStatus_Alerting' && CallDetailEvent === 'CA_CALL_EVENT_ALERTING') {
                        phone.AlertScreenFn(data, 1);
                        this.trigger('alerting', data)
                    }
                    // 咨询振铃弹屏处理
                    if (EventType === 'AgentStatus_Alerting' && CallDetailEvent === 'CA_CALL_EVENT_CONSULT_ALERTING_TP') {
                        phone.AlertScreenFn(data, 1);
                        this.trigger('alerting', data)
                    }
                    if (EventType === 'AgentStatus_Disconnected') {
                        this.trigger('disconnected', data)
                    }
                }
                // 有可能返回值data.Result == 400 停止服务迁出
                var result = data.Result;
                if (result) {
                    phone.customgetStateFn(result)
                }
                phone.toEventType = EventType;
            }
        })
        /*
         * 暴露给用户的 API
         */
    _p(function(P, $) { // 改成监听的那种 方式
            P.fn.defineRenderFn = function(loginingRender, loginRender, explicitNumRender, logoutRender, smallStatusRender) {
                var phone = this;
                if (loginingRender && (typeof loginingRender === 'function')) {
                    phone.renderEvents.loginingRender = loginingRender;
                }
                if (loginRender && (typeof loginRender === 'function')) {
                    phone.renderEvents.loginRender = loginRender;
                }
                if (explicitNumRender && (typeof explicitNumRender === 'function')) {
                    phone.renderEvents.explicitNumRender = explicitNumRender;
                }
                if (logoutRender && (typeof logoutRender === 'function')) {
                    phone.renderEvents.logoutRender = logoutRender;
                }
                if (smallStatusRender && (typeof smallStatusRender === 'function')) {
                    phone.renderEvents.smallStatusRender = smallStatusRender;
                }
            }

            P.fn.create = function() {
                    var phone = this;
                    // 执行 addMenus 之前：
                    // 允许用户通过修改 editor.menus 来自定义配置菜单
                    // 因此要在 create 时执行，而不是 init
                    phone.addAllMenus();
                    // 创建 ucObj 对象
                    //phone.ucObj = new P.UCObj(P.$window[0],P.$document[0]);
                }
                // 存储对接客户时，客户传入的方法，该方法带参数；
                // 每次states 改变 则执行该方法，将state传出
            P.fn.getStates = function(fn) {
                    var phone = this;
                    phone.customgetStateFn = fn; // 将参数传递出去
                }
                //弹屏处理
            P.fn.getAlertScreenFn = function(fn) {
                var phone = this;
                phone.AlertScreenFn = fn; // 将参数传递出去
            }
        })
        /*
         * 最终返回phone构造函数
         */
    return window.newPhone;
})